<?php

class HmNews_HmCategoryController extends Fw_Main
{
	public function listAction()
	{
		$_model = $this->_getModel('HmNewsCategoryDescr');
		$list_category = $_model->getAll();
		$this->view->list_category = $list_category;
		$this->view->rowcount  = count($list_category);
	}
	
	public function addAction()
	{
		$this->validateUser();
		if($this->_request->isPost()){
			$formData = $this->_request->getPost('add');
			if($formData) {
				$data = array('name' => $this->_request->getPost('name'));
				$_model = $this->_getModel('HmNewsCategoryDescr');
				$add_row = $_model->addRow($data);
				return $this->_helper->redirector('list');
			}
		}
	}
	
	public function editAction()
	{
		$this->validateUser();
		$_model = $this->_getModel('HmNewsCategoryDescr');
		$id = (int)$this->_request->getParam('category_id');
		$edit_category = $_model->getRow($id);
		$this->view->edit_category = $edit_category;
		
		if($this->_request->isPost()){
			$formData = $this->_request->getPost('edit');
			if($formData) {
				$data = array('name' => $this->_request->getPost('name'));
				$add_row = $_model->updateRow($id, $data);
				return $this->_helper->redirector('list');
			}
		}
	}
	
	public function deleteAction()
	{
		$this->validateUser();
		$id = (int)$this->_request->getParam('category_id');
		$_model = $this->_getModel('HmNewsCategoryDescr');
		$delete_user = $_model->deleteRow($id);
		return $this->_helper->redirector('list');
	}
}